<template>
  <div class="page">

    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="预约时间：">
          <el-date-picker v-model="formInline.orderTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预约项目：">
          <!-- <project-select v-model="formInline.appointItem"></project-select> -->
          <el-select v-model="formInline.appointItem" class="a_select" placeholder="请选择" clearable>
            <el-option label="拔牙" value="拔牙"></el-option>
            <el-option label="洗牙" value="洗牙"></el-option>
            <el-option label="固定修复" value="固定修复"></el-option>
            <el-option label="活动修复" value="活动修复"></el-option>
            <el-option label="冷光美白" value="冷光美白"></el-option>
            <el-option label="隐适美正畸" value="隐适美正畸"></el-option>
            <el-option label="拍片" value="拍片"></el-option>
            <el-option label="精密修复" value="精密修复"></el-option>
            <el-option label="贴面修复" value="贴面修复"></el-option>
            <el-option label="皓齿美白" value="皓齿美白"></el-option>
            <el-option label="皓得适美白" value="皓得适美白"></el-option>
            <el-option label="儿童牙病治疗" value="儿童牙病治疗"></el-option>
            <el-option label="种植" value="种植"></el-option>
            <el-option label="种植固定修复" value="种植固定修复"></el-option>
            <el-option label="牙周病治疗" value="牙周病治疗"></el-option>
            <el-option label="种植活动修复" value="种植活动修复"></el-option>
            <el-option label="3600体检卡" value="3600体检卡"></el-option>
            <el-option label="补牙" value="补牙"></el-option>
            <el-option label="保持器" value="保持器"></el-option>
            <el-option label="检查" value="检查"></el-option>
            <el-option label="普通正畸" value="普通正畸"></el-option>
            <el-option label="根管治疗" value="根管治疗"></el-option>
            <el-option label="美容修复" value="美容修复"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预约状态：">
          <el-select v-model="formInline.appointStatus" class="a_select" placeholder="请选择" clearable>
            <el-option label="预约" value="预约"></el-option>
            <el-option label="完成" value="完成"></el-option>
            <el-option label="取消" value="取消"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="负责人：">
          <user-select v-model="formInline.principal"></user-select>
        </el-form-item>
        <el-form-item label="传输时间：">
          <el-date-picker v-model="formInline.transferTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="关键词：">
          <el-input v-model="formInline.term" placeholder="请输入姓名/电话/预约编号"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="getList(1)">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <!-- 操作区域 开始 -->
      <div class="action_box">
        <el-button type="default" size="small" :loading="eloading" @click="downloadExcel()">批量导出</el-button>
      </div>
      <!-- 操作区域 end -->

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="departmentName" label="客户信息" width="150">
          <template slot-scope="{row}">
            <tab-user :user="userFormatter(row)" v-if="row" is-custom @click.native="lookDetail(row)"></tab-user>
          </template>
        </el-table-column>
        <el-table-column prop="appointHospital" label="机构名称" />
        <el-table-column prop="appointNo" label="预约编号" />
        <el-table-column prop="appointDate" label="预约日期" />
        <el-table-column prop="appointItem" label="预约项目" />
        <el-table-column prop="appointStatus" label="预约状态" />
        <el-table-column prop="source" label="来源" />
        <el-table-column prop="channel" label="渠道" />
        <el-table-column prop="appointType" label="初复类型" />
        <el-table-column prop="birthday" label="生日" />
        <el-table-column prop="appointRemarks" label="预约备注" />
        <el-table-column prop="cancelReason" label="取消原因" />
        <el-table-column prop="createdDate" label="传输时间" />
        <el-table-column prop="principal" label="负责人" />
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->

  </div>
</template>

<script>
import {GET_APPOINT_SEARCH,GET_APPOINT_EXPORT,GET_CUSTOMER_INFO} from '@/http/inquire.js'
import {
  showModal,
  showToast,
  deepClone,
  broadcast,
  received,
} from "@/common/util";
import { BOOKSTATUSLIST } from "@/common/constants";
import { exportExcel } from "@/common/common";
export default {
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      loading: false,
      BOOKSTATUSLIST,
      showDialog: true,

      // 导出
      eloading: false,
    };
  },
  mounted() {
    let _this = this;
    this.getList();
  },
  methods: {
    // 格式化处理用户信息
    userFormatter(row) {
      let o = deepClone(row);
      o.id = row.clueId;
      o.customerName = o.name;
      o.customerPhone = o.mobile;
      o.pageType = this.id;
      return o;
    },

    /** 获取用户列表 */
    getList(current) {
      let _this = this;
      let oParams = _this.getParams();
      oParams.pageNumber = current || _this.pageNumber;
      _this.loading = true;
      GET_APPOINT_SEARCH(oParams).then((res) => {
        console.log(res);
        _this.loading = false;
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },
    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let o = deepClone(this.formInline);
      let n = o.orderTime || [];
      let m = o.transferTime || []
      if (n && n.length > 0) {
        o.appointBeginDate = n[0];
        o.appointEndDate = n[1];
      }

      if (m && m.length > 0) {
        o.createdBeginDate = m[0];
        o.createdEndDate = m[1];
      }
      o.pageSize = this.pageSize;

      delete o.orderTime;
      delete o.transferTime;
      return o;
    },

    /** 重置 */
    rest() {
      this.formInline = {};
      this.pageNumber = 1;
      this.getList();
    },

    // 导出excel
    downloadExcel() {
      let _this = this;
      let o = deepClone(_this.formInline);
      let m = Object.keys(o);
      if (m.length > 0) {
        showModal({
          message: "确定是否导出筛选条件下面所有预约查询列表?",
          showCancelButton: true,
          type: "warning",
          success: function () {
            _this.dowloadExcelFile();
          },
        });
        return false;
      }

      _this.dowloadExcelFile();
    },

    // 下载excel
    dowloadExcelFile() {
      let _this = this;
      let oParams = _this.getParams();
      let options = {};

      delete oParams.pageNumber;
      delete oParams.pageSize;

      options.method = "GET";
      options.data = oParams;
      options.url = GET_APPOINT_EXPORT;
      options.fileName = "预约查询列表.xlsx";
      _this.eloading = true;
      exportExcel(options).then((res) => {
        _this.eloading = false;
      });
    },

    // 查看详情
    lookDetail(row){
      console.log(row)
      let params = {}
      params.name = row.name;
      params.phone = row.mobile
      GET_CUSTOMER_INFO(params).then(res => {
        let _list = res.data || []
        if(_list.length<=0){
          showToast({
            message:'暂无用户详情'
          })
          return false;
        }
        let _obj = _list[0];
        broadcast("userDetail", _obj);
      })
    }

  },
};
</script>

<style lang="scss" scoped>
</style>
